(function () {
    "use strict";

    angular.module('core').factory('securityService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {
        return {
            signIn: function (login, chaveAcesso, manterConectado) {
                var deferred = $q.defer();
                var args = {
                    login: login,
                    chaveAcesso: chaveAcesso,
                    manterConectado: manterConectado
                };
                $http.post('/security/signin', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            signOut: function () {
                var deferred = $q.defer();
                $http.post('/security/signout')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            getIdentityInfo: function () {
                var deferred = $q.defer();
                $http.post('/security/getidentityinfo')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },

            checkLicenca: function () {
                var deferred = $q.defer();
                $http.post('/security/checklicenca')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            requestLicenca: function () {
                var deferred = $q.defer();
                $http.post('/security/requestlicenca')
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            saveLicenca: function (licenca) {
                var deferred = $q.defer();
                var args = { licenca: licenca };
                $http.post('/security/savelicenca', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getPermiteObjeto: function (args) {
                var deferred = $q.defer();
                $http.post('/security/getPermiteObjeto', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getPermiteClasse: function (args) {
                var deferred = $q.defer();
                $http.post('/security/getPermiteClasse', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
            getPermiteRota: function (args) {
                var deferred = $q.defer();
                $http.post('/security/getPermiteRota', args)
                    .success(function (data) { deferred.resolve(data); })
                    .error(function (data, status, headers, config) { deferred.reject(data); });
                return deferred.promise;
            },
        }
    }

})();


